﻿using System;
using System.Collections.Generic;
using System.Text;

namespace HGZP.PLL
{
   /// <summary>
   /// 描述: 获得当前分页的开始记录号和结束记录号
   /// 作者: 郑文亮
   /// 日期: 2007-4-28 14:02
   /// </summary>
    public class Pagination
    {
        /// <summary>
        /// 初始化pageCount 的数值
        /// </summary>
        /// <param name="myPageSize"></param>
        /// <param name="myMaxRows"></param>
        public void Initialize(int myPageSize, int myMaxRows)
        {
            maxRows = myMaxRows;
            pageSize = myPageSize;
            if (myPageSize != 0)
            {
                pageCount = (myMaxRows / myPageSize);
            }
            else
            {
                throw new Exception("每页图片数量不能为0");
            }
            //取余数
            if ((myMaxRows % myPageSize) > 0)
            {
                pageCount++;
            }
        }
        //条件参数
        public int pageSize = 10; //每页多少条记录
        public int maxRows = 100;   //总共多少条记录
        public int pageCount = 0;   //总共多少页
        public int currentPage = 1;   //当前页
       

        //结果参数
        /// <summary>
        /// 结果中的 起始行号
        /// </summary>
        public int rowStart = 0;   //结果中的 起始行号
        /// <summary>
        /// 结果中的 结束行号
        /// </summary>
        public int rowEnd = 0;     //结果中的 结束行号
        //

        public void GetCurrentStartRowAndEndRow(int myCurrentPage)
        {
            if (myCurrentPage > pageCount)
            { 
                //throw new Exception("总页数为" + pageCount.ToString() + "\r\n您想取的得页数为" + myCurrentPage.ToString() + "\r\n当前页数不能大于总页数"); 
                myCurrentPage = pageCount;
            }
            rowStart = (pageSize * (myCurrentPage - 1)) + 1;
            int myRowEnd = pageSize * myCurrentPage;
            if (myRowEnd > maxRows)
            {
                rowEnd = maxRows;
            }
            else
            {
                rowEnd = myRowEnd;
            }
            //
            currentPage = myCurrentPage;
            //
            
            //
        }
    }
}
